<template>
	<view>
		<view style="width: 694.6rpx;box-sizing: border-box;padding: 47rpx 28.4rpx;margin: 32.6rpx 0 0 28.4rpx;background: #FFFFFF;border-radius: 30.2rpx;">
			<view style="font-size: 35rpx;font-weight: bold;color: #383838;">请写下这节课的总结:</view>
			<view style="margin: 48rpx 0 40rpx 0;">
				<textarea placeholder-style="#D5D5D5" placeholder="请输入这节课教学内容描述..." class="content" confirm-type="next" v-model="cont"/>
			</view>
			<view style="display: flex;flex-wrap: wrap;">
				<view v-for="(itme,index) in img" :key="index" style="margin-right: 45rpx;width: 170rpx;height: 170rpx;position: relative;margin-top: 40rpx;" v-if="img.length != 0">
					<image :src="itme" style="width: 170rpx;height: 170rpx;border-radius: 9.06rpx;border: #D6D6D6 0.09rpx solid;" @tap.stop="cha_kan"></image>
					<view style="width: 50rpx;height: 50rpx;position: absolute;top: -25rpx;left: 135rpx;" @tap.stop="shanchu(index)">
						<image src="../../../static/newshouye/shanchu_cha.png" style="width: 50rpx;height: 50rpx;"></image>
					</view>
				</view>
				<view style="margin-top: 40rpx;">
					<image src="../../../static/newshouye/tijiaotupian.png" style="width: 170rpx;height: 170rpx;"  @tap="addl"></image>
				</view>
			</view>
		</view>
		<view style="position: fixed;width: 648.7rpx;height: 85.76rpx;line-height: 85.76rpx;background: #EE7B30;text-align: center;color: #FFFFFF;font-size: 29rpx;border-radius: 42.9rpx;bottom: 40rpx;left: 50.736rpx;" @tap="gotianjia">
			完成
		</view>
	</view>
</template>
<script>
	import qiniu from "../../../common/qiniuUploader.js"
	export default {
		data(){
			return {
				img: [],
				key: "",
				token: "",
				appointment_id: "",
				master_id: "",
				mechanism_id: "",
				cont: ""
			}
		},
		methods:{
			cha_kan(){
				let me = this
				 uni.previewImage({
					  urls: me.img,
					  indicator: "number"
				 })
			},
			shanchu(index){
				this.img.splice(index,1)
			},
			to(){
				this.key = Math.ceil(Math.random()*1000000)
				uni.request({
					url:"https://www.curiousmore.com/qmore/push/upload/getToken",
					data:{
						key:this.key
					},
					method:"post",
					success:(res) => {
						this.token = res.data.data
					}
				})
			},
			addl(){
				let me = this
				uni.showActionSheet({
				  itemList: ['从手机相册选择', '拍照'],
				  success: function(res) {
					let aa = []
					if(res.tapIndex == 1){
						aa = ["camera"]
					}else{
						aa = ["album"]
					}
					me.to()
					uni.chooseImage({
						count: 1,
						sizeType: ['compressed'],
						sourceType: aa,
						success:(res_) => {
							let filePath = res_.tempFilePaths[0]
							if(me.token != ""){
								qiniu.upload(filePath, (res) => {
									me.img.push(res.fileUrl)
								}, (error) => {
									console.log('error: ' + error);
								}, {
									region: 'ECN',
									domain: 'http://img.curiousmore.com', 
									key: me.key, 
									uptoken: me.token, 
								}, (res) => {
									
								}, () => {
									// 取消上传
								}, () => {
									// `before` 上传前执行的操作
								}, (err) => {
									// `complete` 上传接受后执行的操作(无论成功还是失败都执行)
								});
							}
						}
					})
				  },
				fail: function(res) {
				    console.log(res.errMsg)
				  }
				})
			},
		async	gotianjia(){
				const res = await this.$myRequest({
					url:"/masterSummary/insertSummaryOffline",
					methed:"post",
					data:{
						appointment_id: this.appointment_id.toString(),
						master_id: this.master_id.toString(),
						mechanism_id: this.mechanism_id.toString(),
						content: this.cont,
						photo_url: this.img.toString()
					},
					header:{
						'content-type':'application/json'
					}
				})
				if(res.code == 0){
					uni.reLaunch({
					    url: "/pages/tabBer/newsshouye/newsshouye"
					});
				}else{
					uni.showToast({
						title:res.message,
						icon:"none",
						duration: 3000
					})
				}
			}
		},
		onLoad(option) {
			const val = JSON.parse(decodeURIComponent(option.num))
			console.log(val)
			this.appointment_id = val.id
			this.master_id = val.master_id
			this.mechanism_id = val.mechanism_id
			
		},
		onShow() {
			
		}
	}
</script>
<style lang="scss" scoped>
	.content{
		width: 637rpx;
		height: 328rpx;
		border: 1rpx solid #A3A3A3;
		font-size:26.6rpx ;
		color: #000000;
		padding: 25rpx;
		box-sizing: border-box;
	}
</style>